package com.ruoyi.project.dict.materialTopicAsso.service.impl;

import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.framework.aspectj.lang.annotation.DataSource;
import com.ruoyi.framework.aspectj.lang.enums.DataSourceType;
import com.ruoyi.project.dict.material.domain.Material;
import com.ruoyi.project.dict.material.service.IMaterialService;
import com.ruoyi.project.dict.materialTopicAsso.domain.MaterialTopicAsso;
import com.ruoyi.project.dict.materialTopicAsso.mapper.MaterialTopicAssoMapper;
import com.ruoyi.project.dict.materialTopicAsso.service.IMaterialTopicAssoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 专题资料Service业务层处理
 *
 * @author shixiangwen
 * @date 2022-02-24
 */
@Service
@DataSource(DataSourceType.DICT)
public class MaterialTopicAssoServiceImpl implements IMaterialTopicAssoService {

    @Autowired
    private MaterialTopicAssoMapper materialTopicAssoMapper;

    @Autowired
    private IMaterialService materialService;

    /**
     * 查询专题资料
     *
     * @param id 专题资料ID
     * @return 专题资料
     */
    @Override
    public MaterialTopicAsso selectMaterialTopicAssoById(Long id) {
        return materialTopicAssoMapper.selectMaterialTopicAssoById(id);
    }

    /**
     * 查询专题资料列表
     *
     * @param materialTopicAsso 专题资料
     * @return 专题资料
     */
    @Override
    public List<MaterialTopicAsso> selectMaterialTopicAssoList(MaterialTopicAsso materialTopicAsso) {
        List<MaterialTopicAsso> list = materialTopicAssoMapper.selectMaterialTopicAssoList(materialTopicAsso);
        list.forEach(item -> {
            Material material = materialService.selectMaterialById(item.getMaterialId());
            if (material != null) {
                item.setName(material.getName());
            }
        });
        return list;
    }

    /**
     * 新增专题资料
     *
     * @param materialTopicAsso 专题资料
     * @return 结果
     */
    @Override
    public int insertMaterialTopicAsso(MaterialTopicAsso materialTopicAsso) {
        return materialTopicAssoMapper.insertMaterialTopicAsso(materialTopicAsso);
    }

    /**
     * 修改专题资料
     *
     * @param materialTopicAsso 专题资料
     * @return 结果
     */
    @Override
    public int updateMaterialTopicAsso(MaterialTopicAsso materialTopicAsso) {
        return materialTopicAssoMapper.updateMaterialTopicAsso(materialTopicAsso);
    }

    /**
     * 删除专题资料对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteMaterialTopicAssoByIds(String ids) {
        return materialTopicAssoMapper.deleteMaterialTopicAssoByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除专题资料信息
     *
     * @param id 专题资料ID
     * @return 结果
     */
    @Override
    public int deleteMaterialTopicAssoById(Long id) {
        return materialTopicAssoMapper.deleteMaterialTopicAssoById(id);
    }
}
